<template>
  <div>
    <div>
      <input v-model="inputValue" />
      <button @click="handleSubmit">提交</button>
    </div>
    <ul>
      <!-- ：传值给子组件 @监听子组件的方法 -->
      <todo-item 
       v-for="(item,index) in list"
       :key="index"
       :content='item'
       :index='index'
       @delete='ChildDelete'
       >
        {{item}}
      </todo-item>
    </ul>
  </div>
</template>

<script>
/* 引入一个组件 */
import TodoItem from './components/TodoItem'
export default {
  name: 'todoList',
  components: {
    'todo-item': TodoItem
  },
  data: function () {
    return {
      inputValue: '',
      list: []
    }
  },
  methods: {
    handleSubmit: function () {
      this.list.push(this.inputValue)
      this.inputValue = ''
    },
    ChildDelete (index) {
      this.list.splice(index, 1)
    }
  }
}
</script>

<style></style>
